package com.kede.app.domain;

import lombok.Data;
import io.swagger.annotations.ApiModelProperty;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.bean.copier.CopyOptions;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import javax.persistence.*;
import javax.validation.constraints.*;
import java.math.BigDecimal;
import java.sql.Timestamp;
import java.io.Serializable;

/**
* @description /
* @author Pr.li
* @date 2023-06-06
**/
@Entity
@Data
@Table(name="t_supplies")
@EntityListeners(AuditingEntityListener.class)
public class Supplies implements Serializable {
    /**
    * 
    */
    @ApiModelProperty(value = "id")
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "`id`")
    private Integer id;
    /**
    * 物资名称
    */
    @ApiModelProperty(value = "物资名称")
    @Column(name = "`supplie_name`",nullable = false)
    @NotBlank
    private String supplieName;
    /**
    * 数量
    */
    @ApiModelProperty(value = "数量")
    @Column(name = "`num`",nullable = false)
    @NotNull
    private Integer num;
    /**
    * 交付图片信息
    */
    @ApiModelProperty(value = "交付图片信息")
    @Column(name = "`delivery_img`",nullable = false)
    private String deliveryImg;
    /**
    * 渠道
    */
    @ApiModelProperty(value = "渠道")
    @Column(name = "`channel`")
    private String channel;
    /**
    * 展示图片，给用户看的
    */
    @ApiModelProperty(value = "展示图片，给用户看的")
    @Column(name = "`show_img`")
    private String showImg;
    /**
    * 
    */
    @ApiModelProperty(value = "createBy")
    @Column(name = "`create_by`")
    private String createBy;
    /**
    * 
    */
    @ApiModelProperty(value = "updateBy")
    @Column(name = "`update_by`")
    private String updateBy;
    /**
    * 
    */
    @ApiModelProperty(value = "createTime")
    @Column(name = "`create_time`")
    @CreatedDate
    private Timestamp createTime;
    /**
    * 
    */
    @ApiModelProperty(value = "updateTime")
    @Column(name = "`update_time`")
    @LastModifiedDate
    private Timestamp updateTime;

    @ApiModelProperty(value = "当前剩余数量")
    @Column(name = "curr_num")
    private Integer currNum;

    @ApiModelProperty(value = "每个人购买数量限制")
    @Column(name = "`buy_num`")
    private Integer buyNum;

    @ApiModelProperty(value = "需要多少德币")
    @Column(name = "debi")
    private Integer debi;

    @ApiModelProperty(value = "需要多少rmb")
    @Column(name = "money")
    private BigDecimal money;

    @ApiModelProperty(value = "已兑换数量")
    @Transient
    private Integer exchangeNum;

    public void copy(Supplies source){
        BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true));
    }
}
